package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.GroupTourRegistrationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gtr")

public class GroupTourRegistrationController {

    @Autowired
    private com.example.mountainwalker.service.GroupTourRegistrationService groupTourRegistrationService;

    //http://localhost:8080/gtr/list
    @GetMapping("/list")
    public List<GroupTourRegistrationInfo> getGroupTourRegistrationList() {
        List<GroupTourRegistrationInfo> groupTourRegistrationInfo = groupTourRegistrationService.getGroupTourRegistrationInfo();
        return groupTourRegistrationInfo;
    }

    // http://localhost:8080/gtr/find/1
    @GetMapping("/find/{RegistrationID}")
    public GroupTourRegistrationInfo getGroupTourRegistrationById(@PathVariable Integer RegistrationID){
         GroupTourRegistrationInfo groupTourRegistrationInfo = groupTourRegistrationService.getGroupTourRegistrationInfoById(RegistrationID);
         return groupTourRegistrationInfo;
    }

    // http://localhost:8080/gtr/delete/1
    @DeleteMapping("/delete/{RegistrationID}")
    public int deleteGroupTourRegistrationById(@PathVariable("RegistrationID") Integer RegistrationID) {
        int result = groupTourRegistrationService.deleteGroupTourRegistrationInfoById(RegistrationID);
        System.out.println("删除结果：" + result);  // 添加日志
        return result;
    }

    // http://localhost:8080/gtr/insert
    @PostMapping("/insert")
    public int insertGroupTourRegistrationInfo(@RequestBody GroupTourRegistrationInfo groupTourRegistrationInfo) {
        System.out.println("接受到的数据:"+groupTourRegistrationInfo);
        int result = groupTourRegistrationService.insertGroupTourRegistrationInfo(groupTourRegistrationInfo);
        return result;
    }

    //http://localhost:8080/gtr/update
    @PutMapping("/update")
    public int updateGroupTourRegistrationInfo(@RequestBody GroupTourRegistrationInfo groupTourRegistrationInfo){
        int result= groupTourRegistrationService.updateGroupTourRegistrationInfo(groupTourRegistrationInfo);
        return result;
    }


}
